package com.aaa.springboot.commons.lang;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.Assert;

import java.io.Serializable;

@AllArgsConstructor
@Data
@Accessors(chain = true)
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 4190759762629364239L;
    private  Integer code;
    private  String message;
    private  Long count;
    private  T  data;

    private Result() {
    }

    public  static  <T>Result<T> ok(){
        Result<T> result=new Result<>();

        result.setCode(0).setMessage("处理成功");
        return  result;
    }

    public  static  <T>Result<T> ok(Long count,T data){
        Result<T> result=new Result<>();

        result.setCode(0).setMessage("处理成功").setCount(count).setData(data);
        return  result;
    }


    public  static  <T>Result<T> ok(Long count,String message,T data){
        Result<T> result=new Result<>();

        result.setCode(0).setCount(count).setMessage(message).setData(data);
        return  result;
    }

    public  static  <T>Result<T> ok(T data){
        Result<T> result=new Result<>();
        result.setCode(0).setMessage("处理成功").setData(data);
        return  result;
    }

    public  static  <T>Result<T> fail(){
        Result<T> result=new Result<>();
        result.setCode(400).setMessage("处理失败");
        return  result;
    }

    public  static  <T>Result<T> fail(Integer code,String message){
        Result<T> result=new Result<>();
        result.setCode(code).setMessage(message);
        return  result;
    }

    public  static  <T>Result<T> fail(Integer code,String message,T data){
        Result<T> result=new Result<>();
        result.setData(data).setCode(code).setMessage(message);
        return  result;
    }
}
